package com.fjnldx.mes.controller.common;

import com.fjnldx.mes.domain.domainReq.GetDataDicList;
import com.fjnldx.mes.domain.domainReq.QueryParamReq;
import com.fjnldx.mes.domain.domainRes.Result;
import com.fjnldx.mes.service.common.CommonService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletRequest;

@RestController
@RequestMapping("/common")
@Api(value = "公共接口", tags = "公共模块")
public class CommonController {
    @Autowired
    CommonService commonService;

    @PostMapping("/testTest")
    @ApiOperation(value = "测试测试", notes = "测试测试")
    public Result testTest() throws Exception {
        return commonService.test();
    }

    @PostMapping("/queryDataDictionaryList")
    @ApiOperation(value = "顶部查询栏调用数据字典（组织：organization）（车间：workshop）（工序：working_procedure）（品种：varieties）（细纱设备：xiSha_devSn）", notes = "顶部查询栏调用数据字典")
    public Result queryDataDictionaryList(@RequestBody GetDataDicList data) throws Exception {
        return commonService.queryDataDictionaryList(data);
    }

    @PostMapping("/queryParam")
    @ApiOperation(value = "查询参数", notes = "Api")
    public Result conFc6(@RequestBody QueryParamReq queryParamReq) {
        return commonService.queryParam(queryParamReq);
    }

    /**
     * 图片上传-多张图片
     *
     * @return Result
     */
    @PostMapping(value = "/uploadImage")
    @ApiOperation(value = "单图片上传", notes = "单图片上传")
    public Result conFc5(@RequestParam(value = "file") MultipartFile file, HttpServletRequest request) {
        String url = commonService.uploadImage(file, request);
        return Result.success(url);
    }

    @GetMapping("/test")
    @ApiOperation(value = "测试", notes = "测试")
    public String test() {
        return "mes-server成功";
    }

    @GetMapping("/queryPzByGongXu")
    @ApiOperation(value = "查询各工序对应品种", notes = "查询各工序对应品种")
    public Result queryPzByGongXu(String gongxu) {
        return commonService.queryPzByGongXu(gongxu);
    }
}
